<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>测试手写promise功能</title>
  </head>
  <body>
    <!-- <script src="./1. 实现Promise功能.js"></script> -->
    <script src="./2. 手写一个ajax方法.js"></script>
    <script>
      const p1 = new MyPromise(function (resolve, reject) {
        // resolve(100);
        setTimeout(() => {
          resolve(100);
        }, 1000);
        // reject('throw new error');
      });

      //   console.log(p1);

      const p11 = p1.then((data1) => {
        console.log('data1: ' + data1);
        return data1 + 1;
      });

      const p12 = p11.then((data2) => {
        console.log('data2: ' + data2);
        return data2 + 2;
      });

      const p13 = p12.catch((err) => {
        console.error(err);
      });

      const p2 = MyPromise.resolve(200);
      const p3 = MyPromise.resolve(300);
      const p4 = MyPromise.reject('400 error');

      const p5 = MyPromise.all([p1, p2, p3]);
      //   const p5 = MyPromise.all([p2, p3, p4]);
      const p6 = MyPromise.race([p4, p3]);
    </script>
  </body>
</html>
